import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.UUID;

public class HospitalManager {
    private ArrayList<Department> allDepartments = new ArrayList<>();
    private ArrayList<Doctor> doctors = new ArrayList<>();
    private ArrayList<Appointment> Appointment = new ArrayList<>();
    private Scanner sc = new Scanner(System.in);

    public void star(){
        while(true){
            System.out.println("-------------------------------");
            System.out.println("1.department manager-add department");
            System.out.println("2.department manager-delete department");
            System.out.println("3.department manager-set department");
            System.out.println("4.doctor manager-add doctor");
            System.out.println("5.doctor manager-add doctor");
            System.out.println("6.doctor manager-add doctor");
            System.out.println("7.doctor manager-add doctor");
            System.out.println("8.doctor manager-add doctor");
            Scanner sc = new Scanner(System.in);
            switch(sc.next()){
                case "1":
                    adddepartment();
                    break;
                    case "4":
                        adddoctor();
                        break;
                        case "5":

            }
        }
    }

    private void adddoctor() {
        System.out.println("----------------------------------");
        Doctor doctor = new Doctor();
        while(true){
            System.out.println("Choice doctor's department name: ");
            for(int i =0; i<allDepartments.size(); i++){
                Department department = allDepartments.get(i);
                System.out.println((i+1) + "number," + department.getName());
            }
            System.out.println("Enter doctor's department number: ");
            int command = sc.nextInt();
            if(command < 1||command > allDepartments.size()){
                System.out.println("error");
                continue ;
            }
            Department department = allDepartments.get(command -1);
            doctor.setDepartmentName(department.getName());

            doctor.setDoctorId(UUID.randomUUID().toString());

            System.out.println("Enter doctor's name: ");
            String doctorName = sc.next();
            doctor.setName(doctorName);

            System.out.println("Enter doctor's sex: ");
            String sex = sc.next();
            doctor.setGender(sex);

            System.out.println("Enter doctor's age: ");
            int age = sc.nextInt();
            doctor.setAge(age);

            System.out.println("Enter doctor's specialty: ");
            String specialty = sc.next();
            doctor.setSpecialty(specialty);

            System.out.println("Enter doctor's join date: ");
            String joinDateString = sc.next();
            LocalDate joinDate = LocalDate.parse(joinDateString);
            doctor.setJoinDate(joinDate);

            department.getDoctors().add(doctor);
            System.out.println("Enter success: ");
        }


    }

    private void adddepartment() {
        System.out.println("----------------------------------");
        OUT:
        while (true){
        System.out.print("Enter department name: ");
            String name = sc.nextLine();
            for(int i = 0; i<allDepartments.size(); i++){
                if(allDepartments.get(i).getName().equals(name)){
                    continue OUT;
                }
            }
            Department department = new Department();
            department.setName(name);
            allDepartments.add(department);
            break;
        }
    }
}
